package com.shengqin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shengqin.common.pojo.CommonPage;
import com.shengqin.entity.Arbitrate;
import com.shengqin.mapper.ArbitrateMapper;
import com.shengqin.pojo.exam.ArbitrateQueryParam;
import com.shengqin.service.IArbitrateService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class ArbitrateServiceImpl extends ServiceImpl<ArbitrateMapper, Arbitrate> implements IArbitrateService {


    @Override
    public Page<Arbitrate> queryPage(CommonPage<ArbitrateQueryParam> queryPageParam) {
        ArbitrateQueryParam queryParam = queryPageParam.getQueryParam();
        QueryWrapper<Arbitrate> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Arbitrate::getPlanId,queryParam.getPlanId());
        if(queryParam.getSchoolId() != null){
            wrapper.lambda().eq(Arbitrate::getSchoolId,queryParam.getSchoolId());
        }
        if(StringUtils.hasLength(queryParam.getStudyCode())){
            wrapper.lambda().eq(Arbitrate::getStudyCode,queryParam.getStudyCode());
        }

        wrapper.lambda().orderByDesc(Arbitrate::getId);
        Page<Arbitrate> page = new Page<>(queryPageParam.getPageNo(),queryPageParam.getPageSize());
        page(page,wrapper);
        return page;
    }
}
